Image data obtained from http://www.vision.caltech.edu/Image_Datasets/Caltech101/
In [1]:
DIR = "F:/data/101_ObjectCategories/"
In [2]:
import sys;sys.path.append("C:/Users/jmenard/learning_smoke/scripts")
In [126]:
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt
from skimage.transform import resize as imresize
import skimage.io as skio
import skimage.transform
import pywt
from sklearn.linear_model import Lasso
In [127]:
os.listdir(DIR)[0:10]
Out[127]:
In [128]:
DIR_LOC = DIR+"bonsai/"
In [129]:
os.listdir(DIR_LOC)[0:10]
Out[129]:
In [7]:
len( os.listdir(DIR_LOC) )
Out[7]:
In [8]:
_img = skio.imread(DIR_LOC+"image_0001.jpg")
In [9]:
print(
type(_img),
_img.shape,
_img.dtype
)
In [84]:
plt.imshow(_img[:,:,0])
Out[84]:
In [66]:
_img.shape
Out[66]:
In [113]:
_img_flat = _img[:,:,0].flatten()
In [114]:
_img_flat.shape
Out[114]:
In [115]:
# Get fft coefficients:
_s = np.fft.fft(_img_flat)
re_s = np.real(_s)
im_s = np.imag(_s)
In [116]:
plt.plot(re_s, im_s,linestyle="None",marker=".")
Out[116]:
In [117]:
_s_sorted = np.sort(abs(_s))
In [118]:
thresh_5per = _s_sorted[int(0.05*300*280)]
In [119]:
big_idxs = _s > thresh_5per
_s_cut = np.multiply(_s, big_idxs)
In [120]:
# Get fft coefficients:
_s_cut = np.fft.fft(_img_flat)
re_s_sort = np.real(_s_cut)
im_s_sort = np.imag(_s_cut)
plt.plot(re_s_sort, im_s_sort,linestyle="None",marker=".")
Out[120]:
In [121]:
inv_s = np.fft.ifft(_s_cut)
In [122]:
inv_s.shape
Out[122]:
In [123]:
rec_ = inv_s.reshape(300,280)
In [124]:
plt.imshow( np.real(rec_) )
plt.title("Taking top 5% of fourier coefs")
Out[124]:
In [125]:
plt.imshow(_img[:,:,0])
plt.title("Original")
Out[125]:
In [ ]: